package com.hymjweb.demo.framework.util;

import com.alibaba.fastjson.JSONObject;
import com.hymjweb.demo.framework.util.pojoContrast.ContrastUtils;
import org.slf4j.LoggerFactory;

import javax.sql.rowset.serial.SerialBlob;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Blob;
import java.sql.SQLException;
import java.text.Collator;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 关于数据类型处理的类
 * <p>
 * wjz,0226,增加findMapValueByKey方法
 * 
 * @author william
 */
public final class DataTypeUtil {

    public static String[] getNameArr(String names) {
        names = DataTypeUtil.toNotNullString(names);
        names = names.replace("，", ",");
        names = names.replace(" ", ",");
        names = names.replace("　", ",");
        names = names.replace(".", ",");
        return names.split(",");
    }

    public static int getNamesLen(String names) {
        String[] arr = getNameArr(names);
        return arr.length;
    }

    public static String quoteStr(Object o) {
        return "'" + toNotNullString(o) + "'";
    }

    public static String quoteLeftLikeStr(Object o) {
        return "'%" + toNotNullString(o) + "'";
    }

    public static String quoteRightLikeStr(Object o) {
        return "'" + toNotNullString(o) + "%'";
    }

    public static String quoteAllLikeStr(Object o) {
        return "'%" + toNotNullString(o) + "%'";
    }

    /**
     * 判断child是否是parent的子类
     * 
     * @param parent
     *            Class
     * @param child
     *            Class
     * @return boolean
     */
    public static boolean isChildClass(Class parent, Class child) {

        if (child == null || parent == null){
            return false;
        }

        Class cls = child;
        while (!cls.getName().equals(parent.getName())) {
            cls = cls.getSuperclass();
            if (cls == null) {
                return false;
            }
        }
        return true;
    }

    public static Object invokeMethod(String className, String methodName,

            Object[] args) {
        return invokeMethod(className, methodName, null, args);
    }

    /**
     * 调用Java的方法
     * <p>
     * add by wjz 040825
     * 
     * @param className
     *            String 类名称（包括Package）
     * @param methodName
     *            String 方法名称
     * @param args
     *            Object[] 调用参数
     * @return Object
     */
    public static Object invokeMethod(String className, String methodName, Class[] argsType, Object[] args) {
        try {
            Class cls = Class.forName(className);
            Object obj = null;

            Constructor classConstructor = cls.getConstructor(null);

            Object clsObj = classConstructor.newInstance(null);
            // 有参数类型，直接调用
            if (argsType != null) {
                Method m = cls.getMethod(methodName, argsType);
                if (m == null){
                    return null;
                }

                obj = m.invoke(clsObj, args);
                if (obj == null){
                    return "true";
                }

                return obj;
            }
            Class[] argCls;
            // 如果只有一个同名的，直接调用
            int count = 0;
            Method m = null;
            Method[] ma = cls.getMethods();
            if (ma == null || ma.length == 0) {
                return null;
            }
            for (int i = 0; i < ma.length; i++) {
                if (ma[i] == null || !ma[i].getName().equals(methodName)) {
                    continue;
                }
                m = ma[i];
                count++;

            }
            if (count == 1) {
                obj = m.invoke(clsObj, args);
                if (m.getReturnType() == null && obj == null) {
                    return "true";
                }
                return obj;

            }
            // 存在多个同名函数，需要依次判断
            for (int i = 0; i < ma.length; i++) {
                if (ma[i] == null || !ma[i].getName().equals(methodName)) {
                    continue;
                }
                argCls = ma[i].getParameterTypes();
                if ((argCls == null || argCls.length == 0 || args == null || args.length == 0)) {
                    obj = ma[i].invoke(clsObj, args);
                    if (ma[i].getReturnType() == null && obj == null){
                        return "true";
                    }

                    return obj;

                } else {
                    // 参数长度和类型不一致,则不调用
                    if (argCls.length != args.length){
                        continue;
                    }

                    int j;
                    for (j = 0; j < argCls.length; j++) {
                        if (args[j] == null || args[j].getClass() == null){
                            break;
                        }
                        if (!isChildClass(argCls[j], args[j].getClass())) {
                            break;
                        }
                    }
                    if (j != argCls.length) {
                        continue;
                    }

                    obj = ma[i].invoke(clsObj, args);
                    if (ma[i].getReturnType() == null && obj == null){
                        return "true";
                    }

                    return obj;

                }

            }

            return obj;
        } catch (Throwable ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return null;
        }
    }

    /**
     * 岳老虎 2004-01-13 添加此方法
     * 
     * @param className
     *            类的名称
     * @param argsType
     *            参数名称
     * @param argsValue
     *            参数值
     * @return 返回实例华以后的对象
     */
    public static Object getClassInstance(String className, Class[] argsType, Object[] argsValue) {
        try {
            Class dynamicClass = Class.forName(className);
            Constructor classConstructor = dynamicClass.getConstructor(argsType);
            Object objInstance = classConstructor.newInstance(argsValue);
            return objInstance;
        } catch (Exception ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return null;
        }
    }

    // add by hejiang 20030725
    /**
     * Gets the DateStr attribute of the DataTypeUtil class
     * 
     * @return The DateStr value
     */
    public static synchronized String getDateStr() {
        Date now = new Date();
        String s = DateUtil.getStringDate("yyyy-MMdd-HHmmss");
        return s;
    }

    // add by hejiang

    /**
     * 产生8位随机数（字符串）
     * <p>
     * wujinzhong 0530
     * <p>
     * 
     * @return 对应的整数值,如果出错,则返回Integer.MIN_VALUE
     */

    public static synchronized String getRandomStr() {
        Date now = new Date();
        String s = DateUtil.getStringDate("yyyyMMddHHmmssSSS");
        try {
            Thread.sleep(1);
        } catch (Exception ex) {
            //NutzUtil.getLogger().error("FATAL ERROR! get random string fail", ex);
        }
        return s;
        // return Long.toString(now.getTime());
        // return String.valueOf((int) (Math.random() * 100000000));

    }

    /**
     * 对Hashtable的键值排序 wjz 0830
     * 
     * @param ht
     *            Description of Parameter
     * @return Description of the Returned Value
     */

    public static Object[] getSortedKey(Hashtable ht) {
        if (ht == null) {
            return null;
        }

        try {
            Vector v = new Vector(ht.keySet());
            Collections.sort(v);
            Object[] keys = v.toArray();
            return keys;
        } catch (Exception ex) {
            //NutzUtil.getLogger().error("sort error", ex);
            return ht.keySet().toArray();
        }

    }

    // end by add

    /**
     * 产生8位随机数（整形）
     * 
     * @param bt1
     *            Description of Parameter
     * @param bt2
     *            Description of Parameter
     * @return 对应的整数值,如果出错,则返回Integer.MIN_VALUE
     */
    // public static int getRandomInt() {
    // return (int) (Math.random() * 100000000);
    // }
    // end by add
    /**
     * 产生8位随机数（整形） 产生8位随机数（整形） 产生8位随机数（整形） 产生8位随机数（整形） 产生8位随机数（整形） 产生8位随机数（整形）
     * 产生8位随机数（整形） 产生8位随机数（整形） 产生8位随机数（整形） 判断两个字节数组是否相等
     * 
     * @param bt1
     *            Description of Parameter
     * @param bt2
     *            Description of Parameter
     * @return 对应的整数值,如果出错,则返回Integer.MIN_VALUE
     * @return The BytesEquals value
     */
    public static boolean isBytesEquals(byte[] bt1, byte[] bt2) {
        if (bt1.length != bt2.length) {
            return false;
        }
        for (int i = 0; i < bt1.length; i++) {
            if (bt1[i] != bt2[i]) {
                return false;
            }
        }
        return true;
    }

    /**
     * obj的字符串表示形式是否为空字符串（null或"")
     * <p>
     * add by wjz 040401
     * 
     * @param obj
     *            目标对象
     * @return 其字符串形式为null或""返回为true,否则为false
     */
    public static boolean isEmptyStr(Object obj) {
        if (obj == null) {
            return true;
        }
        try {
            String s = obj.toString();
            if (s == null || s.trim().length() == 0) {
                return true;
            }
            return false;
        } catch (Exception ex) {
            return false;
        }
    }

    /**
     * @author zhang yong on 20181105
     * 判断某个对象是否为空，是则抛出有指定信息的异常
     * @param obj 对象名
     * @param msg 显示信息
     */
    public static void isEmptyStrThenThrow(Object obj, String msg) throws Exception {
        if(isEmptyStr(obj)) {
           throw new Exception(msg);
        }
    }

    /**
     * @author zhang yong on 20181105
     * 判断某个条件是否为真，为真则抛出有指定信息的异常
     * @param flag
     * @param msg
     */
    public static void isTrueThenThrow(boolean flag, String msg) {
        if(flag) {
            //throw new WarningException(msg);
        }
    }

    public static boolean isEmptyAll(Object[] arr) {
        if (arr == null || arr.length <= 0) {
            return true;
        }
        for (int i = 0; i < arr.length; i++) {
            if (!DataTypeUtil.isEmptyStr(arr[i])){
                return false;
            }
        }
        return true;
    }

    public static boolean isEmptyAll(Object[][] objs) {
        if (objs == null || objs.length <= 0){
            return true;
        }
        for (int i = 0; i < objs.length; i++) {
            for (int j = 0; j < objs[0].length; j++) {
                if (!DataTypeUtil.isEmptyStr(objs[i][j])){
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 字节数组反向查找
     * 
     * @param source
     *            Description of Parameter
     * @param search
     *            Description of Parameter
     * @param start
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static int byteBackwardIndexOf(byte[] source, byte[] search, int start) {
        int iRet = -1;
        int i = start;
        do {
            if (i <= 0) {
                break;
            }
            if (i - search.length < 0) {
                iRet = -1;
                break;
            }
            if (isBytesEquals(subBytes(source, (i - search.length) + 1, i), search)) {
                iRet = (i - search.length) + 1;
                break;
            }
            i--;
        } while (true);
        return iRet;
    }

    /**
     * 字节数组查找
     * 
     * @param source
     *            Description of Parameter
     * @param search
     *            Description of Parameter
     * @param start
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static int byteIndexOf(byte[] source, byte[] search, int start) {
        int iRet = -1;
        int i = start;
        do {
            if (i >= source.length) {
                break;
            }
            if (i + search.length > source.length) {
                iRet = -1;
                break;
            }
            if (isBytesEquals(subBytes(source, i, (i + search.length) - 1), search)) {
                iRet = i;
                break;
            }
            i++;
        } while (true);
        return iRet;
    }

    /**
     * 为一个二维数组增加或减少列
     * 
     * @author wujinzhong 050530
     * @param data
     *            Object[][]
     * @param cloumnsCount
     *            int 增加或减少的列数，正数表示增加列，负数表示减少列
     * @return Object[][]
     */
    public static Object[][] addArrayColumns(Object[][] data, int cloumnsCount) {
        if (data == null){
            return null;
        }

        if (cloumnsCount == 0){
            return data;
        }

        int col_len = data[0].length + cloumnsCount;
        int row_len = data.length;
        Object[][] data2 = new Object[row_len][col_len];
        int copy_col_len;// 实际要拷贝的列数
        if (cloumnsCount >= 0) {
            copy_col_len = data[0].length;
        } else {
            copy_col_len = col_len;
        }
        for (int i = 0; i < row_len; i++) {
            System.arraycopy(data[i], 0, data2[i], 0, copy_col_len);
        }
        return data2;
    }

    /**
     * 合并数组
     * 
     * @param arr1
     * @param arr2
     * @param removeRepeated
     *            是否去掉重复的
     * @return 返回合并后的数组
     */
    public static Object[] mergeArr(Object[] arr1, Object[] arr2, boolean removeRepeated) {
        if (!removeRepeated) {
            List<Object> list = new ArrayList<Object>();
            arr_add2list(arr1, list);
            arr_add2list(arr2, list);
            if (list.size() > 0) {
                return list.toArray(new Object[list.size()]);
            }
        } else {
            LinkedHashMap<Object, Object> m = new LinkedHashMap<Object, Object>();
            arr_add2map(arr1, m);
            arr_add2map(arr2, m);
            if (m.size() > 0) {
                Object[] new_arr = new Object[m.size()];
                int i = 0;
                for (Iterator<Object> iterator = m.keySet().iterator(); iterator.hasNext();) {
                    Object key = iterator.next();
                    new_arr[i] = key;
                    i++;
                }
                return new_arr;
            }
        }
        return null;
    }

    private static void arr_add2list(Object[] arr, List<Object> list) {
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                list.add(arr[i]);
            }
        }
    }

    private static void arr_add2map(Object[] arr, HashMap<Object, Object> map) {
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                map.put(arr[i], null);
            }
        }
    }

    /**
     * 将字节数组转换为16进制字符串如 {10,-1}-->0aFF
     * 
     * @param src
     *            源数组
     * @return 字符串,null表示失败
     * @roseuid 3C15CF9502F8
     */
    public static String bytes2Hexs(byte[] src) {

        StringBuffer hs = new StringBuffer();
        String stmp = "";
        hs.setLength(src.length * 2);
        int t = 0;
        try {

            for (int n = 0; n < src.length; n++) {
                stmp = (Integer.toHexString(src[n] & 0XFF));
                if (stmp.length() == 1) {
                    hs.setCharAt(t, '0');
                    t++;
                    hs.setCharAt(t, stmp.charAt(0));
                    t++;
                } else {
                    hs.setCharAt(t, stmp.charAt(0));
                    t++;
                    hs.setCharAt(t, stmp.charAt(1));
                    t++;
                }
            }
        }
        // try
        catch (NullPointerException ex) {
            return null;
        }
        String strTemp = hs.toString().toUpperCase();
        hs = null;
        return strTemp;
    }

    /**
     * 字节数组拷贝
     * 
     * @param source
     *            源字节数组
     * @param dest
     *            目标字节数组
     * @param len
     *            拷贝长度
     * @return 0－成功 >0表示失败,值为对应ERROR_CODE
     * @roseuid 3C183B36025A
     */
    public static int bytesCopy(byte[] source, byte[] dest, int len) {
        try {
            for (int i = 0; i < len; i++) {
                dest[i] = source[i];
            }

            return 0;
        } catch (Exception ex) {
            return 100;
        }
    }

    /**
     * 从HashMap中查找某个keyd的值,支持递归查找
     * <p>
     * add by wjz 0226
     * 
     * @param map
     *            Description of the Parameter
     * @param key
     *            Description of the Parameter
     * @return Description of the Return Value
     */
    public static Object findMapValueByKey(Map map, Object key) {
        if (map == null || key == null) {
            return null;
        }
        Object[] keys = map.keySet().toArray();
        if (keys == null) {
            return null;
        }
        int len = keys.length;
        Object key2 = null;
        for (int i = 0; i < len; i++) {
            key2 = keys[i];
            if (key2 == null) {
                continue;
            }
            if (key2.equals(key)) {
                return map.get(key2);
            }
            Object v1 = map.get(key2);
            if (v1 != null && v1 instanceof Map) {
                Object v2 = findMapValueByKey((Map)v1, key);
                if (v2 != null) {
                    return v2;
                }
            }
        }
        return null;
    }

    /**
     * 将16进制字符串转换为字节数组如 0aFF-->{10,-1}
     * 
     * @param src
     *            字符串
     * @return 目标数组,null表示失败
     * @roseuid 3C15D0230126
     */
    public static byte[] hexs2Bytes(String src) {
        try {

            int len = src.length() / 2;
            int itemp;
            String stmp;
            if (src.length() % 2 == 1) {
                return null;
            }
            byte[] bt = new byte[len];

            for (int i = 0; i < len; i++) {
                stmp = src.substring(i * 2, i * 2 + 2);
                // itemp = Integer.decode("0x" + stmp).intValue() - 256;
                itemp = Integer.decode("0x" + stmp).intValue();
                bt[i] = (byte)itemp;

            }
            return bt;
        } catch (NumberFormatException e) {
            return null;
        }
    }

    /**
     * The main program for the DataTypeUtil class
     * 
     * @param args
     *            The command line arguments
     */
    public static void main(String[] args) {

        System.out.println(removeFromStrArr("2,2,2,3", "2", ","));

        HashMap m22 = new HashMap();
        m22.put("oper", "add");
        System.out.println(addUrlParameter("http://www.baidu.com", m22));
        System.out.println(addUrlParameter("http://www.baidu.com?name=123", m22));

        System.out.println("a,b,c".replace(",", "_"));
        System.out.println(getVersion("v1.0.6"));
        System.out.println(getUUID());
        System.out.println(removeFromStrArr("4", "4", ","));

        if (true) {
            String s1 = "530100123456789040906365     ";
            // String s1 = "吴金中";
            byte[] bt = strToBCD(s1);
            System.out.println("bt.length" + bt.length);
            System.out.println("s1.length" + s1.length());
            String s = BCDToStr(bt);
            System.out.println("s=" + s + "】");


            System.exit(0);
        }

        if (true) {
            Object[] args2 = new Object[1];
            // Object a="100.1";
            // args2[0]=a;
            Object obj = invokeMethod("zxt.pub.util.DataTypeUtil", "toInt", new Object[] { "100.09" });
            System.exit(0);
        }
        // Number[] num={new Double(99),new Double(99.01)};
        // Number[] num={new Integer(99),new Integer(100)};
        HashMap m = new HashMap();
        m.put("t1", "aaa");
        HashMap m1 = new HashMap();
        HashMap m11 = new HashMap();
        m1.put("m11", m11);
        m11.put("HY_DM", "bbba");
        m11.put("HY_DM2", "bc");
        m.put("m1", m1);
        if (true) {
            System.err.println(findMapValueByKey(m, "HY_DM"));
            System.exit(0);
        }
        Number[] num = { new Integer(99), new Double(99.000001) };
        System.err.println(maxNum(num).doubleValue());

        System.err.println(minNum(num).doubleValue());
        // Hashtable ht = new Hashtable();
        //
        // ht.put("03", "外资年报");
        // ht.put("01", "增值税一般人");
        // ht.put("04", "外资季报");
        // ht.put("02", "增值税小规模");
        // NutzUtil.getLogger().debug(ht);
        // NutzUtil.getLogger().debug(sortHashTable(ht));
        // double test = 1340196656.1 - 3653636 - 6019.08 - 45646547 - 77437 -
        // 1340196656.1;
        // System.out.println("round 前： " + test);
        // System.err.println("round 后： " + round(test + "", 2));
    }

    /**
     * 根据数据类型sjlx,对SRC进行处理
     * 
     * @param src
     *            Description of Parameter
     * @param errCode
     *            Description of Parameter
     * @param sjlx
     *            Description of Parameter
     * @return Description of the Returned Value
     */

    public static byte[] manageBytes(byte[] src, StringBuffer errCode, String sjlx) {
        byte[] bt2 = src;
        if("1".equals(sjlx.substring(0, 1))){
            return null;
        }
        if ("1".equals(sjlx.substring(2, 3))) {
            return null;
        }
        return bt2;
    }

    /**
     * 取得一组数中的最大值
     * <p>
     * modified by wjz 1005:change intValue to doubleValue
     * </p>
     * 
     * @param iArr
     *            Description of Parameter
     * @return
     */
    public static Number maxNum(Number[] iArr) {
        if (iArr == null || iArr.length <= 0) {
            return null;
        }
        Number rtn = iArr[0];
        for (int i = 1; i < iArr.length; i++) {
            if (rtn.doubleValue() > iArr[i].doubleValue()) {
                continue;
            }
            if (rtn.doubleValue() < iArr[i].doubleValue()) {
                rtn = iArr[i];
                continue;
            }
        }
        return rtn;
    }

    /**
     * 取得一组数中的最小值
     * <p>
     * modified by wjz 1005:change intValue to doubleValue
     * </p>
     * 
     * @param iArr
     *            Description of Parameter
     * @return
     */
    public static Number minNum(Number[] iArr) {
        if (iArr == null || iArr.length <= 0) {
            return null;
        }
        Number rtn = iArr[0];
        for (int i = 1; i < iArr.length; i++) {
            if (rtn.doubleValue() < iArr[i].doubleValue()) {
                continue;
            }
            if (rtn.doubleValue() > iArr[i].doubleValue()) {
                rtn = iArr[i];
                continue;
            }
        }
        return rtn;
    }

    /**
     * 打印字符数组 {10,FF} type=0打印10：-1 type=1打印0A：FF
     * 
     * @param src
     *            将要打印的数组
     * @param type
     *            0-打印字符的十进制值，1－打印字符的十六进制值
     * @return 结果字符串
     * @roseuid 3C183E6F030A
     */
    public String printCharArray(String src, int type) {
        return null;
    }

    /**
     * 打印对象的内容
     * <p>
     * wujinzhong 0604,040922
     * </P>
     * 
     * @param obj
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static String printObject(Object obj) {
        StringBuffer sb = new StringBuffer();
        if (obj == null) {
            return "null";
        }
        if (obj instanceof HashMap) {
            HashMap map = (HashMap)obj;
            Iterator keys = map.keySet().iterator();
            while (keys.hasNext()) {
                sb.append("\t");
                Object key = keys.next();
                sb.append("key=" + key);
                sb.append(printObject(map.get(key)));
                sb.append("\n");
            }
            return sb.toString();
        } else if (obj instanceof ArrayList) {

            ArrayList ary = (ArrayList)obj;
            Iterator values = ary.iterator();
            while (values.hasNext()) {
                sb.append("\t");
                sb.append(printObject(values.next()));
                sb.append("\n");
            }

            return sb.toString();
        } else if (obj instanceof byte[]) {
            byte[] bts = (byte[])(obj);
            sb.append("size=" + bts.length + ",data={");
            for (int i = 0; i < bts.length; i++) {
                sb.append(bts[i] + ",");
            }
            sb.append("}");
            return sb.toString();
        } else {
            return obj.toString();
        }

    }

    /**
     * 四舍五入算法
     * 
     * @param strNumber
     *            四舍五入前的字符串
     * @param cont
     *            小数点后保留的位数
     * @return 四舍五入以后 的字符串
     */
    public static String round(String strNumber, int cont) {
        int mi = 1;
        for (int i = 0; i <= cont; i++) {
            mi = mi * 10;
        }
        if (DataTypeUtil.isEmptyStr(strNumber)) {
            strNumber = "0";
        }
        double d = new Double(strNumber).doubleValue();
        BigDecimal number = new BigDecimal(d * mi);
        BigInteger integer = new BigInteger("0");
        int end = Integer.parseInt(number.toBigInteger().toString().substring(number.toBigInteger().toString().length() - 1));
        if (end >= 5) {
            if (d > 0) {
                integer = number.toBigInteger().add(new BigInteger("10"));
            } else {
                integer = number.toBigInteger().subtract(new BigInteger("10"));
            }
        } else {
            integer = number.toBigInteger();
        }
        integer = integer.divide(new BigInteger("10"));
        number = new BigDecimal(integer, cont);
        return number.toString();
    }

    /**
     * 对Hashtable排序 wjz 0830
     * 
     * @param ht
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static Hashtable sortHashTable(Hashtable ht) {
        if (ht == null || ht.size() == 0) {
            return ht;
        }
        try {

            // ht.put("03", "外资年报");
            // ht.put("01", "增值税一般人");
            // ht.put("04", "外资季报");
            // ht.put("02", "增值税小规模");
            Vector v = new Vector(ht.keySet());
            // zxt.pub.util.NutzUtil.getLogger().debug(v);
            Collections.sort(v);
            Object[] keys = v.toArray();
            int len = ht.size();
            Hashtable ht2 = new Hashtable(len);
            for (int i = 0; i < len; i++) {

                ht2.put(keys[i], ht.get(keys[i]));
            }
            return ht2;
        } catch (Exception ex) {
            //NutzUtil.getLogger().error("sort error", ex);
            return ht;
        }

    }

    public static String sortNames(String names, String splitChar) {
        if (isEmptyStr(names)){
            return names;
        }
        Comparator<Object> com = Collator.getInstance(java.util.Locale.CHINA);
        String[] newArray = names.split(splitChar);
        Arrays.sort(newArray, com);
        String s = "";
        for (String i : newArray) {
            if (!isEmptyStr(s)){
                s += splitChar;
            }

            s += i;
            // System.out.print(i + " ");
        }
        return s;
    }

    /**
     * 取子数组
     * 
     * @param source
     *            Description of Parameter
     * @param from
     *            Description of Parameter
     * @param end
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static byte[] subBytes(byte[] source, int from, int end) {
        if (from > end || end > source.length - 1) {
            return null;
        }
        byte[] btRet = new byte[(end - from) + 1];
        for (int i = 0; i <= end - from; i++) {
            btRet[i] = source[i + from];
        }

        return btRet;
    }

    /**
     * Description of the Method
     * 
     * @param foo
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static byte[] toByteArray(short foo) {
        return toByteArray(foo, new byte[2]);
    }

    /**
     * Description of the Method
     * 
     * @param foo
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static byte[] toByteArray(int foo) {
        return toByteArray(foo, new byte[4]);
    }

    /**
     * Description of the Method
     * 
     * @param foo
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static byte[] toByteArray(long foo) {
        return toByteArray(foo, new byte[8]);
    }

    /**
     * Description of the Method
     * 
     * @param foo
     *            Description of Parameter
     * @param array
     *            Description of Parameter
     * @return Description of the Return Value
     * @eturn Description of the Returned Value
     */
    private static byte[] toByteArray(long foo, byte[] array) {
        for (int iInd = 0; iInd < array.length; iInd++) {
            array[iInd] = (byte)((foo >> (iInd * 8)) & 0x000000FF);
        }
        return array;
    }

    /**
     * 将字符串转换为中文
     * 
     * @param src
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static String toCHNString(String src) {
        if (src == null || src.length() <= 0) {
            return src;
        }
        try {
            return new String(src.getBytes("ISO-8859-1"), "GBK");
        } catch (java.io.UnsupportedEncodingException ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return null;
        }
    }

    public static String utf8Togb2312(String str) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            switch (c) {
                case '+':
                    sb.append(' ');
                    break;
                case '%':
                    try {
                        sb.append((char)Integer.parseInt(str.substring(i + 1, i + 3), 16));
                    } catch (Exception e) {
                        //NutzUtil.getLogger().error(e.getMessage(), e);
                        sb.append("%");
                    }
                    i += 2;
                    break;
                default:
                    sb.append(c);
                    break;
            }
        }
        // Undo conversion to external encoding
        String result = sb.toString();
        String res = null;
        try {
            byte[] inputBytes = result.getBytes("8859_1");
            res = new String(inputBytes, "UTF-8");
        } catch (Exception e) {
        }
        return res;
    }

    /**
     * ADD BY YQL2005-07-01 将字符串转换为中文ISO-8859-1字符集
     * 
     * @param src
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static String GBKtoISOString(String src) {
        if (src == null || src.length() <= 0) {
            return src;
        }
        try {
            return new String(src.getBytes("GBK"), "ISO-8859-1");
        } catch (java.io.UnsupportedEncodingException ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return null;
        }
    }

    /**
     * ADD BY YQL2005-07-01 将字符串转换为中文ISO-8859-1字符集
     * 
     * @param src
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static String GB2312toISOString(String src) {
        if (src == null || src.length() <= 0) {
            return src;
        }
        try {
            return new String(src.getBytes("GB2312"), "ISO-8859-1");
        } catch (java.io.UnsupportedEncodingException ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return null;
        }
    }

    /**
     * 将字符串转换为中文GBK字符集
     * 
     * @param src
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static String toGBKString(String src) {
        if (src == null || src.length() <= 0) {
            return src;
        }
        try {
            return new String(src.getBytes("ISO-8859-1"), "GBK");
        } catch (java.io.UnsupportedEncodingException ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return null;
        }
    }

    /**
     * 转换为Dobule，否则返回null
     * @param o
     * @return
     */
    public static Double toDouble(Object o){
        try {
            String s = o.toString().trim();
            if(s!=null && !"".equals(s)){
                if(isNumber(s)){
                    return toDouble(s,-1,2);
                }
                return  null;
            }
            else{
                return  null;
            }
        } catch (Exception ex) {
            return  null;
        }
    }

    /**
     * 将对象转换为浮点数 add by wjz 1119
     * @param o 源对象
     * @param forceConvert 是不是强制转换
     * @return 对应的浮点数
     */
    public static double toDouble(Object o, boolean forceConvert) throws Exception {
        try {
            String s = o.toString().trim();
            return Double.parseDouble(s);
        } catch (Exception ex) {
            if (forceConvert) {
                return 0;
            }
            throw new Exception("数值：" + o + "，为空或不是一个合法的浮点数");
        }
    }

    /**
     * 将对象转换为浮点数 add by wjz 1119
     * @param o 源对象
     * @param defaultDouble 转换错误时，返回默认值
     * @param scale 转后保留精度
     * @return 对应的浮点数
     */
    public static double toDouble(Object o, double defaultDouble, int scale) {
        try {
            if (o == null) {
                return defaultDouble;
            }
            String s = o.toString().trim();
            return toBigDecimal(s, new BigDecimal(defaultDouble)).setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
        } catch (Exception ex) {
            return defaultDouble;
        }
    }

    /**
     * 将对象转换为浮点数 add by wjz 1119
     * @param o 源对象
     * @param defaultDouble 转换错误时，返回默认值
     * @return 对应的浮点数
     */
    public static double toDouble(Object o, double defaultDouble) {
        return toDouble(o, defaultDouble, 2);
    }

    /**
     * Description of the Method
     * 
     * @param src
     *            Description of Parameter
     * @return Description of the Returned Value
     */
    public static String toHexsFormat(byte[] src) {
        if (src == null) {
            return null;
        }
        int len = src.length;
        StringBuffer sb = new StringBuffer();

        String s = "";
        sb.append(",value=");

        for (int i = 0; i < len; i++) {
            s = Integer.toHexString(src[i] & 0XFF);
            if (s.length() == 1) {
                sb.append("0");
            }
            sb.append(s);
            sb.append(",");
        }
        return sb.substring(0, sb.length() - 1);
    }

    /**
     * 根据四个字节的物理存储,生成一个整数
     * <p>
     * 例如e0,08,00,00生成整数2272
     * <p>
     * wujinzhong 0610
     * 
     * @param bts
     *            Description of Parameter
     * @return The Int value
     */
    public static int toInt(byte[] bts) {
        if (bts == null) {
            return Integer.MIN_VALUE;
        }
        int v = 0;
        int len = bts.length;
        for (int i = len - 1; i >= 0; i--) {
            v = v * 256 + ((bts[i] + 256) % 256);

        }
        return v;
    }

    /**
     * 将对象转换为整数型
     * 
     * @param o
     *            源对象
     * @return 对应的Int值,如果出错,则返回Integer.MIN_VALUE
     */
    public static int toInt(Object o) {
        if (o == null) {
            throw new IllegalArgumentException("该对象为空");
        }
        String s = o.toString().trim();
        try {
            return Integer.parseInt(s);
        } catch (Exception ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return Integer.MIN_VALUE;
        }
    }

    /**
     * 转整数对象
     * @param o
     * @return
     */
    public static Integer toInteger(Object o){
        if(o == null){
            return null;
        }
        try {
            if (o instanceof BigDecimal) {
                return ((BigDecimal)o).intValue();
            } else if (o instanceof String) {
                String s = o.toString().trim();
                return new BigDecimal(s).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
            }
            return new BigDecimal(o.toString()).intValue();
        } catch (Exception ex) {
            return null;
        }
    }

    /**
     * 将对象转换为整数型
     * 
     * @param o
     *            源对象
     * @param defaultInt
     * @return 对应的Int值,如果出错,则返回defaultInt
     */
    public static int toInt(Object o, int defaultInt) {
        if (o == null){
            return defaultInt;
        }

        try {
            if (o instanceof BigDecimal) {
                return ((BigDecimal)o).intValue();
            } else if (o instanceof String) {
                String s = o.toString().trim();
                return new BigDecimal(s).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
            }
            return new BigDecimal(o.toString()).intValue();
        } catch (Exception ex) {
            return defaultInt;
        }
    }

    /**
     * 将对象转换为整数型
     * 
     * @param o
     *            源对象
     * @return 对应的Long值,如果出错,则返回Long.MIN_VALUE
     */
    public static long toLong(Object o) {
        if (o == null) {
            throw new IllegalArgumentException("该对象为空");
        }
        String s = o.toString().trim();
        try {
            return Long.parseLong(s);
        } catch (Exception ex) {
            //NutzUtil.getLogger().error(ex.getMessage(), ex);
            return Long.MAX_VALUE;
        }
    }

    /**
     * 如果不是能转为Long则返回null
     * @param o
     * @return
     */
    public static Long toLongObject(Object o){
        try {
            if (o == null) {
                throw new IllegalArgumentException("该对象为空");
            }
            String s = o.toString().trim();
            return new Long(s);
        } catch (Exception ex) {
            return null;
        }
    }

    /**
     * 将对象转换为Long整型
     * 
     * @param o
     *            源对象
     * @param defaultLong
     * @return 对应的long值,如果出错,则返回defaultLong
     */
    public static long toLong(Object o, long defaultLong) {
        try {
            if (o == null){
                return defaultLong;
            }
            if (o instanceof BigDecimal) {
                return ((BigDecimal)o).longValue();
            }
            return new BigDecimal(o.toString()).longValue();
        } catch (Exception ex) {
            return defaultLong;
        }
    }

    /**
     * 将对象转换为BigDecimal整型
     * 
     * @param o
     *            源对象
     * @param defaultBigDecimal
     * @return 对应的BigDecimal值,如果出错,则返回defaultBigDecimal
     */
    public static BigDecimal toBigDecimal(Object o, BigDecimal defaultBigDecimal) {
        try {
            return new BigDecimal(o.toString().trim());
        } catch (Exception ex) {
            return defaultBigDecimal;
        }
    }

    /**
     * 从Vector转换为字符串数组的形式 add by yql 1129
     * 
     * @param vec
     * @return
     */
    public static String[] vecToStrArr(Vector vec) {
        if (vec == null) {
            return null;
        }
        int iLen = vec.size();
        String[] rtnArr = new String[iLen];
        for (int i = 0; i < iLen; i++) {
            rtnArr[i] = vec.elementAt(i).toString();
        }
        return rtnArr;
    }

    /**
     * 返回对象的字符串表现，如果为空则返回"" add by wjz 040902
     * 
     * @param obj
     *            Object
     * @return String
     */
    public static String toNotNullString(Object obj) {
        if (obj == null){
            return "";
        }
        return obj.toString();
    }

    public static String toStringObject(Object obj){
        if (obj == null){
            return null;
        }
        if("".equals(obj.toString())){
            return null;
        }
        return obj.toString();
    }

    /**
     * 将BCD码还原为字符串，目前不支持汉字
     * <p>
     * add by wjz 040916
     * 
     * @param bt
     *            byte[] BCD格式的数组
     * @return String
     */
    public static String BCDToStr(byte[] bt) {
        String s = "";
        if (bt == null){
            return "";
        }
        byte[] bt2 = new byte[bt.length * 2];
        byte b = 0;
        byte b1 = 0;
        byte b2 = 0;
        char c = 0;
        try {
            int len = bt2.length;
            int pos = 0;
            for (int i = 0; i < bt.length; i++) {
                b = bt[i];
                bt2[i * 2] = (byte)(bt[i] >> 4 & 0x0f); // 高位
                bt2[i * 2 + 1] = (byte)(bt[i] & 0x0f); // 低位

            }
            boolean flag = true; // 一个字符的开始
            for (int i = 0; i < len; i++) {
                b = bt2[i];
                if (flag) {
                    if (b <= 9) {
                        s = s + (char)(b + 0x30);
                    } else {
                        flag = false;
                    }
                } else { // 不是开始，与前面合并
                    if (b == 0x0f && (i == len - 1)){
                        continue;
                    }

                    s = s + (char)((bt2[i - 1] << 4) + b - 128);

                    flag = true;

                }
            }
            return s;
        } catch (Exception ex) {
            //NutzUtil.getLogger().error("BCDToStr ERROR:" + ex.getMessage(), ex);
            return null;
        }

    }

    /**
     * 将字符串转换为BCD码，目前不支持汉字
     * <p>
     * add by wjz 040916
     * 
     * @param s
     *            String
     * @return byte[] BCD格式的数组
     */
    public static byte[] strToBCD(String s) {
        byte[] bt = new byte[s.length()];
        // 初始化
        for (int i = 0; i < bt.length; i++) {
            bt[i] = (byte)0xff;
        }
        char[] chars = s.toCharArray();
        byte c = 0;
        try {
            int len = chars.length;
            int pos = 0;
            boolean flag = true; // true-high position;false-lower position
            for (int i = 0; i < len; i++) {
                c = (byte)(chars[i]);
                if (c >= '0' && c <= '9') { // 数字
                    if (!flag) { // 低字节
                        bt[pos] = (byte)(bt[pos] + (c - 0x30));
                        flag = true;
                        pos++;
                    } else { // 高字节
                        bt[pos] = (byte)((c - 0x30) << 4);
                        flag = false;
                    }
                } else { // 字符
                    if (!flag) { // 低字节
                        bt[pos] = (byte)((bt[pos]) + (byte)((c + 128) >> 4));
                        pos++;
                        bt[pos] = (byte)(c << 4);
                    } else { // 高字节
                        bt[pos] = (byte)(c + 128);
                        pos++;
                    }

                }

            }
            if (!flag) {
                bt[pos] = (byte)(bt[pos] + 0x0f);
                pos++;
            }
            byte[] ret = new byte[pos];
            System.arraycopy(bt, 0, ret, 0, pos);
            return ret;
        } catch (Exception ex) {
            //NutzUtil.getLogger().error("strToBCD ERROR:" + ex.getMessage(), ex);
            return null;
        }

    }

    public static Integer parseInteger(Object o, Integer defaulti) {
        try {
            return new Integer(Integer.parseInt(o.toString()));
        } catch (Exception e) {
            return defaulti;
        }
    }

    public static Double parseDouble(Object o, Double defaulti) {
        try {
            return new Double(Double.parseDouble(o.toString()));
        } catch (Exception e) {
            return defaulti;
        }
    }

    public static Float parseFloat(Object o, Float defaulti) {
        try {
            return new Float(Float.parseFloat(o.toString()));
        } catch (Exception e) {
            return defaulti;
        }
    }

    public static Long parseLong(Object o, Long defaulti) {
        try {
            return new Long(Long.parseLong(o.toString()));
        } catch (Exception e) {
            return defaulti;
        }
    }

    public static BigDecimal parseBigDecimal(Object o, BigDecimal defaulti) {
        try {
            return new BigDecimal(o.toString());
        } catch (Exception e) {
            return defaulti;
        }
    }

    public static Date parseDate(Object o, Date defaulti) {
        if (o instanceof Date) {
            return (Date)o;
        }
        try {
            return DateUtil.strToDate(o.toString());
        } catch (Exception e) {
            return defaulti;
        }
    }

    public static Long[] StringArr2LongArr(Object[] ss) {
        if (ss == null) {
            return null;
        }
        List<Long> list = new ArrayList<Long>();
        for (int i = 0; i < ss.length; i++) {
            String s = (ss[i] + "").trim().replaceAll(",", "");
            if (!isNumber(s)) {
                //NutzUtil.getLogger().error(s + ":不是数字!");
            } else {
                list.add(Long.parseLong(s));
            }
        }
        return list.toArray(new Long[0]);
    }

    public static long[] StringArr2longArr(Object[] ss) {
        Long[] arr = StringArr2LongArr(ss);
        if (arr == null || arr.length <= 0) {
            return null;
        }
        long[] retArr = new long[arr.length];
        for (int i = 0; i < arr.length; i++) {
            retArr[i] = arr[i].longValue();
        }
        return retArr;
    }


    public static int getChnLength2(Object o) {
        String str = DataTypeUtil.toNotNullString(o);
        int len;
        int i;
        len = 0;
        for (i = 0; i < str.length(); i++) {
            if (str.charAt(i) > 255) {
                len += 2;
            } else {
                len++;
            }
        }
        return len;
    }

    public static int getChnLength(Object o) {
        String str = DataTypeUtil.toNotNullString(o);
        int len;
        int i;
        len = 0;
        for (i = 0; i < str.length(); i++) {
            if (str.charAt(i) > 255){
                len += 3;
            }
            else{
                len++;
            }

        }
        return len;
    }

    public static String getPrefixStr(Object o, int maxlen) {
        String svalue = o + "";
        int len;
        int i;
        len = 0;
        StringBuffer sb = new StringBuffer(maxlen);
        for (i = 0; i < svalue.length(); i++) {
            if (svalue.charAt(i) > 255){
                len += 2;
            }
            else{
                len++;
            }
            if (len > maxlen){
                break;
            }
            sb.append(svalue.charAt(i));
        }
        return sb.toString();
    }

    public static String htmlAscii2str(String asciistr) {
        // asciistr:&#48;&#49;0&#45;89&#49;&#57;&#48;&#49;&#54;&#48;
        // 变成：010-89190160
        if (DataTypeUtil.isEmptyStr(asciistr)) {
            return "";
        }
        String[] arr = asciistr.split("&#");
        if (arr == null || arr.length <= 1){
            return asciistr;
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            String tmpstr = arr[i];
            if (arr[i].indexOf(";") >= 0) {
                // 45;89
                String[] arr2 = tmpstr.split(";");
                sb.append(assic2str(arr2[0]));
                if (arr2.length >= 2) {
                    for (int j = 1; j < arr2.length; j++) {
                        sb.append(arr2[j]);
                    }
                }
            } else {
                sb.append(tmpstr);
            }
        }
        return sb.toString();
    }

    public static String assic2str(String assicstr) {
        try {
            return (char)Integer.parseInt(assicstr) + "";
        } catch (Exception e) {
            return assicstr;
        }
    }

    public static boolean isMail(String email) {
        // TODO Auto-generated method stub
        if (DataTypeUtil.isEmptyStr(email)) {
            return false;
        }
        if (email.indexOf("@") < 0) {
            return false;
        }
        for (int i = 0; i < email.length(); i++) {
            String ss = email.charAt(i) + "";
            if (DataTypeUtil.isHasChiness(ss)){
                return false;
            }
        }
        return true;
    }

    public static boolean isQQ(String qq) {
        // TODO Auto-generated method stub
        if (DataTypeUtil.isEmptyStr(qq)){
            return false;
        }
        try {
            Long.parseLong(qq);
        } catch (Exception e) {
            // TODO: handle exception
            return false;
        }
        return true;
    }

    public static boolean isHasChiness(String s) {
        if (DataTypeUtil.isEmptyStr(s)){
            return false;
        }
        if (s.getBytes().length != s.length()){
            return true;
        }
        return false;
    }

    public static boolean isAllChiness(String s) {
        if (DataTypeUtil.isEmptyStr(s)){
            return false;
        }
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            String s1 = new String(new char[] { c });
            if (!isHasChiness(s1)){
                return false;
            }
        }
        return true;
    }

    public static int randomInt(int start, int end) {
        double d = Math.random() * (end - start + 1) + start;
        return (int)d;
    }

    public static double randomDouble(double start, double end) {
        double d = Math.random() * (end - start + 1) + start;
        return d;
    }

    public static String addStrRight(Object o, int maxlen, String addstr) {
        return addStrRight(o, maxlen, addstr, false, 1);
    }

    public static String addStrRight(Object o, int maxlen, String addstr, boolean removeMore, int oneChnLen) {
        String s = DataTypeUtil.toNotNullString(o);

        int len = 0;
        if (oneChnLen == 1){
            len = s.length();
        }
        else if (oneChnLen == 2){
            len = DataTypeUtil.getChnLength2(o);
        }
        else if (oneChnLen == 3){
            len = DataTypeUtil.getChnLength(o);
        }
        if (len < maxlen) {
            int j = maxlen - len;
            for (int i = 0; i < j; i++) {
                s += addstr;
            }
        } else if (len > maxlen) {
            if (removeMore){
                s = s.substring(0, maxlen);
            }
        }
        return s;
    }

    public static String addStrLeft(Object o, int maxlen, String addstr) {
        return addStrLeft(o, maxlen, addstr, false, 1);
    }

    public static String addStrLeft(Object o, int maxlen, String addstr, boolean removeMore, int oneChnLen) {
        String s = DataTypeUtil.toNotNullString(o);

        int len = 0;
        if (oneChnLen == 1){
            len = s.length();
        }
        else if (oneChnLen == 2){
            len = DataTypeUtil.getChnLength2(o);
        }
        else if (oneChnLen == 3){
            len = DataTypeUtil.getChnLength(o);
        }
        if (len < maxlen) {
            int j = maxlen - len;
            for (int i = 0; i < j; i++) {
                s = addstr + s;
            }
        } else if (len > maxlen) {
            if (removeMore){
                s = s.substring(len - maxlen);
            }
        }
        return s;
    }

    private static String __ENCODE__ = "GBK";// 一定要是GBK
    private static String __SERVER_ENCODE__ = "GB2312"; // 服务器上的缺省编码

    public static int compare(String s1, String s2) {
        String m_s1 = null, m_s2 = null;
        try {
            // 先将两字符串编码成GBK
            m_s1 = new String(s1.getBytes(__SERVER_ENCODE__), __ENCODE__);
            m_s2 = new String(s2.getBytes(__SERVER_ENCODE__), __ENCODE__);
        } catch (Exception ex) {
            return s1.compareTo(s2);
        }
        int res = chineseCompareTo(m_s1, m_s2);
        System.out.println("比较：" + s1 + " | " + s2 + "==== Result: " + res);
        return res;
    }

    // 获取一个汉字/字母的Char值
    public static int getCharCode(String s) {
        if (s == null && "".equals(s)){
            return -1; // 保护代码
        }
        byte[] b = s.getBytes();
        int value = 0;
        // 保证取第一个字符（汉字或者英文）
        for (int i = 0; i < b.length && i <= 2; i++) {
            value = value * 100 + b[i];
        }
        return value;
    }

    // 比较两个字符串
    public static int chineseCompareTo(String s1, String s2) {
        int len1 = s1.length();
        int len2 = s2.length();
        int n = Math.min(len1, len2);
        for (int i = 0; i < n; i++) {
            int s1_code = getCharCode(s1.charAt(i) + "");
            int s2_code = getCharCode(s2.charAt(i) + "");
            if (s1_code != s2_code){
                return s1_code - s2_code;
            }
        }
        return len1 - len2;
    }

    public static boolean isInArr(Object[] arr, Object o) {
        return getInArrIndex(arr, o) != -1;
    }

    public static boolean isInArr(int[] arr, int o) {
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] == o) {
                    return true;
                }
            }
        }
        return false;
    }

    public static int getInArrIndex(Object[] arr, Object o) {
        if (o == null) {
            return -1;
        }
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null && arr[i].equals(o)) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static boolean isInArr(String strarr, String s) {
        return isInArr(str2arr(strarr), s);
    }

    public static String arr2str(Object[] arr) {
        return arr2str(arr, ",");
    }

    public static String arr2str(Object[] arr, String split) {
        String s = "";
        if (arr != null && arr.length > 0) {
            for (int i = 0; i < arr.length; i++) {
                if (i != 0) {
                    s += split;
                }
                s += DataTypeUtil.toNotNullString(arr[i]).trim();
            }
        }
        return s;
    }

    public static String[] str2arr(Object s) {
        return str2arr(s, ",");
    }

    public static String[] str2arr(Object s1, String splitchar) {
        if (isEmptyStr(s1)) {
            return null;
        }
        String s = DataTypeUtil.toNotNullString(s1);
        s = s.replace("，", splitchar);
        s = s.replace(" ", splitchar);
        s = s.replace("　", splitchar);
        return s.split(splitchar);
    }

    public static Long[] str2LongArr(Object s) {
        return str2LongArr(s, ",");
    }

    public static Long[] str2LongArr(Object s, String splitchar) {
        String[] arr = str2arr(DataTypeUtil.toNotNullString(s), splitchar);
        return StringArr2LongArr(arr);
    }

    public static String MapKey2Str(HashMap m, String split) {
        if (m == null || m.keySet().size() <= 0) {
            return "";
        }
        String s = "";
        for (Iterator iterator = m.keySet().iterator(); iterator.hasNext();) {
            String key = DataTypeUtil.toNotNullString(iterator.next());
            if (!DataTypeUtil.isEmptyStr(s)) {
                s += split;
            }
            s += key;
        }
        return s;
    }

    /**
     * 打印Map的key和value
     * 
     * @param m
     * @param split
     *            kv与kv之间的分割符号
     * @param quoteChar
     *            value的引号
     * @return 例如split=" ",quoteChar="\"" 时返回： key1="value1" key2="value2"
     */
    public static String MapKeyValue2Str(HashMap m, String split, String quoteChar) {
        if (m == null || m.keySet().size() <= 0) {
            return "";
        }
        String s = "";
        for (Iterator iterator = m.keySet().iterator(); iterator.hasNext();) {
            String key = DataTypeUtil.toNotNullString(iterator.next());
            String value = DataTypeUtil.toNotNullString(m.get(key));
            if (!DataTypeUtil.isEmptyStr(s)) {
                s += split;
            }
            s += key + "=" + quoteChar + value + quoteChar;
        }
        return s;
    }

    public static String MapValue2Str(HashMap m, String split) {
        if (m == null || m.keySet().size() <= 0) {
            return "";
        }
        String s = "";
        for (Iterator iterator = m.keySet().iterator(); iterator.hasNext();) {
            String value = DataTypeUtil.toNotNullString(m.get(iterator.next()));
            if (!DataTypeUtil.isEmptyStr(s)) {
                s += split;
            }
            s += value;
        }
        return s;
    }

    /**
     * 从指定的keys从Map中取出value序列
     * 
     * @param m
     *            map
     * @param keys
     *            多个用分隔符隔开
     * @param split
     *            分隔符，例如逗号,
     * @return
     */
    public static String MapValue2StrByKeys(HashMap m, String keys, String split) {
        if (m == null || m.keySet().size() <= 0) {
            return "";
        }
        if (DataTypeUtil.isEmptyStr(keys)) {
            return "";
        }
        String[] keyArr = keys.split(",");
        String s = "";
        for (int i = 0; i < keyArr.length; i++) {
            String value = DataTypeUtil.toNotNullString(m.get(keyArr[i]));
            if (!DataTypeUtil.isEmptyStr(s)) {
                s += split;
            }
            s += value;
        }
        return s;
    }

    public static Object[][] Map2Objs(HashMap m) {
        if (m == null || m.keySet().size() <= 0) {
            return null;
        }
        Object[][] objs = new Object[m.size()][2];
        int i = 0;
        for (Iterator iterator = m.keySet().iterator(); iterator.hasNext();) {
            String key = DataTypeUtil.toNotNullString(iterator.next());
            String value = DataTypeUtil.toNotNullString(m.get(key));
            objs[i][0] = key;
            objs[i][1] = value;
            i++;
        }
        return objs;
    }

    public static boolean isNumChar(char c) {
        return c >= '0' && c <= '9';
    }

    public static boolean isNumber(String s) {
        try {
            new BigDecimal(s);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public static long getVersion(String sVersion) {
        if (DataTypeUtil.isEmptyStr(sVersion)) {
            return Long.MIN_VALUE;
        }
        long l = 0;
        StringBuffer sb = new StringBuffer();
        char[] cs = sVersion.toCharArray();
        for (int i = 0; i < cs.length; i++) {
            char c = cs[i];
            if (isNumChar(c)) {
                sb.append(c);
            }
        }
        String s = sb.toString();
        if (DataTypeUtil.isEmptyStr(s)) {
            return Long.MIN_VALUE;
        }
        return Long.parseLong(s);
    }

    /**
     * 转全角的函数(SBC case) 任意字符串 全角字符串 全角空格为12288，半角空格为32
     * 其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248
     */
    public static String ToQJ(Object o_input) {
        String input = DataTypeUtil.toNotNullString(o_input);
        // 半角转全角：
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 32) {
                c[i] = (char)12288;
                continue;
            }
            if (c[i] < 127) {
                c[i] = (char)(c[i] + 65248);
            }
        }
        return new String(c);
    }

    /**
     * 转半角的函数(DBC case) 任意字符串 半角字符串 全角空格为12288，半角空格为32
     * 其他字符半角(33-126)与全角(65281-65374)的对应关系是：均相差65248
     */
    public static String ToBJ(Object o_input) {
        String input = DataTypeUtil.toNotNullString(o_input);
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 12288) {
                c[i] = (char)32;
                continue;
            }
            if (c[i] > 65280 && c[i] < 65375) {
                c[i] = (char)(c[i] - 65248);
            }
        }
        return new String(c);
    }

    /**
     * 给二维数组列表顶端添加一个空白行
     * 
     * @param objs
     * @param whenIsOnlyOneRowNotAdd
     *            当二维数组仅有一行时，是否添加空白行，true不添加，false添加，默认是true
     * @return
     */
    public static Object[][] addEmpty_2Arr(Object[][] objs, boolean whenIsOnlyOneRowNotAdd) {
        if (objs == null || objs.length <= 0) {
            return objs;
        }
        if (objs.length == 1 && whenIsOnlyOneRowNotAdd) {
            return objs;
        }
        Object[] arr = objs[0];
        int column_len = arr.length;
        Object[][] ret = new Object[objs.length + 1][column_len];
        for (int i = 0; i < ret.length; i++) {
            if (i == 0) {
                for (int j = 0; j < column_len; j++) {
                    ret[i][j] = "";
                }
            } else {
                for (int j = 0; j < column_len; j++) {
                    ret[i][j] = objs[i - 1][j];
                }
            }
        }
        return ret;
    }

    /**
     * 根据二维数组生成Html Select标签下的 option串
     * 
     * @param objs
     * @param whenIsOnlyOneRowNotAdd
     *            whenIsOnlyOneRowNotAdd 当二维数组仅有一行时，是否添加空白行，true不添加，false添加，默认是true
     * @return
     */
    public static String createSelectOptionsStr(Object[][] objs, boolean whenIsOnlyOneRowNotAdd) {
        return createSelectOptionsStr(objs, null, whenIsOnlyOneRowNotAdd);
    }

    /**
     * 根据二维数组生成Html Select标签下的 option串
     * 
     * @param objs
     *            二维数组
     * @param value
     *            指定默认选择的项目，根据值来指定
     * @param whenIsOnlyOneRowNotAdd
     *            whenIsOnlyOneRowNotAdd 当二维数组仅有一行时，是否添加空白行，true不添加，false添加，默认是true
     * @return
     */
    public static String createSelectOptionsStr(Object[][] objs, String value, boolean whenIsOnlyOneRowNotAdd) {
        Object[][] tmpObjs = addEmpty_2Arr(objs, whenIsOnlyOneRowNotAdd);
        if (tmpObjs != null && tmpObjs.length > 0) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < tmpObjs.length; i++) {
                sb.append("<option value='");
                sb.append(DataTypeUtil.toNotNullString(tmpObjs[i][0]));
                sb.append("'");
                if (!DataTypeUtil.isEmptyStr(value) && value.equals(DataTypeUtil.toNotNullString(tmpObjs[i][0]))) {
                    sb.append(" selected ");
                }
                sb.append(">");
                sb.append(DataTypeUtil.toNotNullString(tmpObjs[i][1]));
                sb.append("</option>");
            }
            return sb.toString();
        }
        return null;
    }

    /**
     * 创建Html Select标签
     * 
     * @param selectHtmlId
     *            select框的HTML Id
     * @param property
     *            加到select标签内的属性，可以是方法或者样式
     * @param objs
     *            select框内容
     * @param value
     *            select框默认选择哪个
     * @param whenIsOnlyOneRowNotAdd
     *            当内容仅有一行时，是否添加空白行，true不添加，false添加，默认是true
     * @return
     */
    public static String CreateSelect(String selectHtmlId, String property, Object[][] objs, String value, boolean whenIsOnlyOneRowNotAdd) {
        String s = "<select id='" + selectHtmlId + "' name='" + selectHtmlId + "' " + (DataTypeUtil.isEmptyStr(property) ? "" : property) + ">";
        s += createSelectOptionsStr(objs, value, whenIsOnlyOneRowNotAdd);
        s += "</select>";
        return s;
    }

    public static Object[] toObjArr(Object... values) {
        if (values == null) {
            return null;
        }
        Object[] oarr = new Object[values.length];
        for (int i = 0; i < values.length; i++) {
            oarr[i] = values[i];
        }
        return oarr;
    }

    public static long getMaxValue(long[] values) {
        long max = values[0];
        for (int i = 0; i < values.length; i++) {
            if (max < values[i]) {
                max = values[i];
            }
        }
        return max;
    }

    public static String getMaxValue(String[] values) {
        long[] lv = new long[values.length];
        for (int i = 0; i < lv.length; i++) {
            lv[i] = Long.parseLong(values[i]);
        }
        return String.valueOf(getMaxValue(lv));
    }

    public static long getMinValue(long[] values) {
        long min = values[0];
        for (int i = 0; i < values.length; i++) {
            if (min > values[i]) {
                min = values[i];
            }
        }
        return min;
    }

    public static String getMinValue(String[] values) {
        long[] lv = new long[values.length];
        for (int i = 0; i < lv.length; i++) {
            lv[i] = Long.parseLong(values[i]);
        }
        return String.valueOf(getMinValue(lv));
    }

    public static String getMinValue(String values) {
        return getMinValue(values.split(","));
    }

    public static String getAccessDatabaseUrl(String fn, String MicrosoftAccessDriver) {
        String mdbSysDirver = "Microsoft Access Driver (*.mdb)";
        String CfgMdbSysDirver = MicrosoftAccessDriver;
        if (!DataTypeUtil.isEmptyStr(CfgMdbSysDirver)) {
            mdbSysDirver = CfgMdbSysDirver;
        }
        mdbSysDirver = "{" + mdbSysDirver + "}";
        String mdburl = "jdbc:odbc:driver=" + mdbSysDirver + ";DBQ=" + fn;
        return mdburl;
    }

    /**
     * 类似于ORACLE NVL函数
     * 
     * @param o
     * @param reto
     * @return
     */
    public static String NVL(Object o, Object reto) {
        if (isEmptyStr(o)) {
            return DataTypeUtil.toNotNullString(reto);
        }
        return DataTypeUtil.toNotNullString(o);
    }

    public static void arr2Map(Object[] arr, HashMap<String, String> m) {
        if (arr != null) {
            for (int i = 0; i < arr.length; i++) {
                String key = DataTypeUtil.toNotNullString(arr[i]);
                m.put(key, key);
            }
        }
    }

    public static void str2Map(String s, HashMap<String, String> m) {
        if (DataTypeUtil.isEmptyStr(s)) {
            return;
        }
        String[] arr = s.split(",");
        arr2Map(arr, m);
    }

    public static String refineMessage(String s) {
        if (s == null) {
            return "";
        }
        s = s.replaceAll("\t", "");
        s = s.replaceAll("\n", "");
        s = s.replaceAll(",", "，");
        s = s.replaceAll("'", "’");
        s = s.replaceAll("\"", "”");
        return s;
    }



    /**
     * 获取UUID，去掉"-"符号
     * 
     * @return
     */
    public static String getUUID() {
        UUID uuid = UUID.randomUUID();
        String str = uuid.toString();
        // 去掉"-"符号
        String temp = str.replaceAll("-", "").toLowerCase();
        return temp;
    }

    /**
     * 给定一个字符串分隔，从字符串分隔里删除一个
     * 
     * @param strArr
     * @param s
     * @param SPLIT
     * @return
     */
    public static String removeFromStrArr(String strArr, String s, String SPLIT) {
        if (DataTypeUtil.isEmptyStr(strArr)) {
            return "";
        }
        if (DataTypeUtil.isEmptyStr(s)) {
            return strArr;
        }
        String[] arr = strArr.split(SPLIT);
        return arr2str(removeFromArr(arr, s), SPLIT);
    }

    /**
     * 给定一个字符串数组，从字符串删除一个
     * 
     * @return
     */
    public static String[] removeFromArr(String[] strArr, String s) {
        if (strArr == null || strArr.length <= 0) {
            return strArr;
        }
        if (DataTypeUtil.isEmptyStr(s)) {
            return strArr;
        }
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < strArr.length; i++) {
            if (!strArr[i].equals(s)) {
                list.add(strArr[i]);
            }
        }
        return list.toArray(new String[0]);
    }

    /**
     * 给URL添加参数
     * 
     * @param url
     * @param parametersMap
     * @return
     * @author 檀宇
     * @serialData 2018年1月10日
     */
    public static String addUrlParameter(String url, HashMap parametersMap) {
        if (isEmptyStr(url)) {
            return url;
        }
        String kv = MapKeyValue2Str(parametersMap, "&", "");
        if (url.indexOf("?") >= 0) {
            return url + "&" + kv;
        } else {
            return url + "?" + kv;
        }
    }

    /**替换符串中的换行，空格,制表符,换页符并将它们转换成'symbol'分割的字符返回
     * 如: ad dt/t /fasd/nas -> ad,dt,asd,as
     *    as  ->  as,
     * @param str
     * @param symbol
     * @return 能以','分割的字符串
     * @author 余伟
     * @serialData 2018年3月20日
     */
    public static String replaceSpaceAndTabAndEnterToSymbol(String str, String symbol) {
        if (isEmptyStr(str)) {
            return str;
        }
        // 去除首尾空格
        str = str.trim();
        // 替换中间的 任何空白字符，包括空格、制表符、换页符
        str = str.replaceAll("\\s+", symbol);
        if (str.indexOf(",") == -1) {
            str = str + ",";
        }
        return str;
    }



    /**
     * 因为数据是UTF-8编码，对中文排序很不友好，所以需要添加此方法，保证中文排序正确
     * @param dbColumnName
     * @return 
     * @author tanshiliang
     * @serialData 2018年6月19日
     */
    public static String getNLSSort(String dbColumnName) {
        return "NLSSORT(" + dbColumnName + ",'NLS_SORT = SCHINESE_PINYIN_M')";// 处理oracle的汉字不准确排序问题
        // return "convert(" + dbColumnName + " using gbk)";//处理mysql的汉字不准确排序问题
    }

    /**
     * 去重
     * @param arr
     * @return
     */
    public static String[] deleteRepeatedString(String[] arr) {
        Object[] objArr = deleteRepeatedObject(arr);
        if (objArr == null || objArr.length <= 0) {
            return arr;
        }
        String[] retArr = new String[objArr.length];
        for (int i = 0; i < retArr.length; i++) {
            retArr[i] = DataTypeUtil.toNotNullString(objArr[i]);
        }
        return retArr;
    }

    /**
     * 去重
     * @param arr
     * @return
     */
    public static Object[] deleteRepeatedObject(Object[] arr) {
        if (arr == null || arr.length <= 0) {
            return arr;
        }
        LinkedHashMap<Object, Object> m = new LinkedHashMap<Object, Object>();
        for (int i = 0; i < arr.length; i++) {
            m.put(arr[i], null);
        }
        return m.keySet().toArray(new Object[0]);
    }

    /**
     * 去重
     * @return
     */
    public static String deleteRepeatedName(List<String> listName) {
        if (listName == null || listName.size() <= 0) {
            return "";
        }
        String[] arr = DataTypeUtil.deleteRepeatedString(listName.toArray(new String[0]));
        return DataTypeUtil.arr2str(arr);
    }
    
    /**
     * excel表格上传时，规范手机号
     * @param mobileStr
     * @return 
     * @author 曾婷
     * @serialData 2019年1月7日
     */
    public static String refineMobile(String mobileStr) {
        String mobile = null;
        if (!DataTypeUtil.isEmptyStr(mobileStr)) {
            try {
                double memberCell = Double.parseDouble(mobileStr);
                DecimalFormat df = new DecimalFormat("#");
                mobile = df.format(memberCell);
            } catch (NumberFormatException e) {
                return mobileStr;
            }
        }
        return mobile;
    }
    
    public static int getMonth(Object oMonth) {
        String month = toNotNullString(oMonth);
        month = month.replaceAll("\\.0", "");
        return toInt(month, -1);
    }

    public static boolean isBetween(Long v, Long start, Long end) {
        return isBetween(v.longValue(), start.longValue(), end.longValue());
    }

    public static boolean isBetween(long v, long start, long end) {
        return start <= v && v <= end;
    }

    public static boolean isBetween(Double v, Double start, Double end) {
        return isBetween(v.doubleValue(), start.doubleValue(), end.doubleValue());
    }

    public static boolean isBetween(double v, double start, double end) {
        return start <= v && v <= end;
    }

    public static <T> boolean isEmptyCollection(Collection<T> c) {
        return null == c || c.size() <= 0;
    }

    public static void closeStreams(Closeable... closeables) {
        Arrays.stream(closeables).forEach(closeable -> {
            if(closeable != null) {
                try {
                    closeable.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    
    /**
     * 检验list是否有重复的
     * @param list
     * @return 
     * @author tansl
     * @serialData 2019年3月1日
     */
    public static <T> boolean isRepeated(List<T> list) {
        if (list != null && list.size() > 0) {
            if (list.size() > list.stream().distinct().count()) {
                return true;
            }
        }
        return false;
    }
    
    
    /**
     * 生成6位随机数,主要用于做客户接口系统登录id
     * @return
     */
    public static long createRandomCode() {
        return (long) ((Math.random() * 9 + 1) * 100000);
    }

    public static Blob stringToBlob(String s) {
        if (null == s) {
            return null;
        }
        Blob blob = null;
        try {
            blob = new SerialBlob(s.getBytes());
        } catch (SQLException e) {
            LoggerFactory.getLogger(ContrastUtils.class).error(e.getMessage());
        }
        return blob;
    }

    /**
     * 根据obj获取所有声明方法及父级对象的声明方法
     * @param o
     * @return
     */
    public static Field[] getSuperField(Object o){
        List<Field> f = new ArrayList();
        Class cls = o.getClass();
        while (cls != null && cls != Object.class){
            Field[] fields = cls.getDeclaredFields();
            for (Field field : fields) {
                f.add(field);
            }
            cls = cls.getSuperclass();
        }
        return f.toArray(new Field[0]);
    }

    /**
     * 第一个字符大写
     * @param propName
     * @return
     */
    public static String firstCharUpper(String propName) {
        if (DataTypeUtil.isEmptyStr(propName)) {
            return propName;
        }
        if (propName.length() == 1) {
            return propName.toUpperCase();
        }
        return propName.substring(0, 1).toUpperCase() + propName.substring(1, propName.length());
    }

    /**
     * 根据get方法获取对象上的某个属性
     * @param o
     * @param propertyName
     * @return
     * @throws IntrospectionException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public static Object invokeMethod(Object o,String propertyName) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
        Class<?> clazz = o.getClass();
        PropertyDescriptor pd = new PropertyDescriptor(propertyName, clazz);
        Method readMethod = pd.getReadMethod();
        Object obj = readMethod.invoke(o);
        return obj;
    }


    /**
     * 下划线转驼峰处理
     */

    private static Pattern linePattern = Pattern.compile("_(\\w)");

    /** 下划线转驼峰 */
    public static String lineToHump(String str) {
        str = str.toLowerCase();
        Matcher matcher = linePattern.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

    /** 驼峰转下划线(简单写法，效率低于{@link #humpToLine2(String)}) */
    public static String humpToLine(String str) {
        return str.replaceAll("[A-Z]", "_$0").toLowerCase();
    }

    private static Pattern humpPattern = Pattern.compile("[A-Z]");

    /** 驼峰转下划线,效率比上面高 */
    public static String humpToLine2(String str) {
        Matcher matcher = humpPattern.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

    /**
     * 将带有下划线的mapkey转为驼峰式的mapkey，返回的是列表对象
     * @param maps
     * @return
     */
    public static List<Map<String,Object>> lineMapToHumpMap(List<Map<String,Object>> maps){
        List<Map<String,Object>> newMaps = new ArrayList<>();
        for(Map<String,Object> mapObj : maps){
            newMaps.add(lineMapToHumpMap(mapObj));
        }
        return newMaps;
    }

    /**
     * 不产生新对象，在分页时使用
     * @param maps
     * @return
     */
    public static List<Map<String,Object>> lineMapToHumpMap2(List<Map<String,Object>> maps){
        for(Map<String,Object> mapObj : maps){
            List<String> keyArray = new ArrayList<>();
            List<Object> valueArray = new ArrayList<>();
            for(Map.Entry<String,Object> entry:mapObj.entrySet()){
                String key=entry.getKey();
                String lineToHumpKey = lineToHump(key);
                Object value = entry.getValue();
                keyArray.add(lineToHumpKey);
                valueArray.add(value);
            }

            Iterator<Map.Entry<String, Object>> iterator = mapObj.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, Object> next = iterator.next();
                if (next.getKey() != null) {
                    iterator.remove();
                }
            }

            for(int i=0;i<keyArray.size();i++){
                mapObj.put(keyArray.get(i),valueArray.get(i));
            }
        }
        return maps;
    }


    /**
     * 将带有下划线的mapkey转为驼峰式的mapkey
     * @param maps
     * @return
     */
    public static Map<String,Object> lineMapToHumpMap(Map<String,Object> maps){
        Map<String,Object> newMapObj = new HashMap<>();
        for(Map.Entry<String,Object> entry : maps.entrySet()){
            String key = lineToHump(entry.getKey());
            Object value = entry.getValue();
            newMapObj.put(key,value);
        }
        return newMapObj;
    }

    /**
     * jsonObject 转 Map
     * @param jsonObject
     * @return
     */
    public static Map<String,Object> jsonObjectToMap(JSONObject jsonObject){
        if(jsonObject == null || jsonObject.isEmpty()){
            return null;
        }

        Map<String,Object> paramMap = new HashMap<>();
        Iterator iterator = jsonObject.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<String,Object> entry = (Map.Entry<String, Object>) iterator.next();
            paramMap.put(entry.getKey(),entry.getValue());
        }
        return paramMap;

    }



    /**
     * 递归获取obj的上的id值。特殊情况：有的pojo继承了父pojo
     * @return
     * @throws IllegalAccessException
     */
    public static Object getIdValueFromObj(Object object) throws IllegalAccessException {

        if(object instanceof String){
            // 字符串值中两边会有带有"引号，所以要去除这些引号
            String value = object.toString();
            value = value.replace("\"","");
            return value;
        }

        Class cls = object.getClass();
        if(cls!=null){
            while (cls != Object.class){
                Field[] fields = cls.getDeclaredFields();
                for (Field field : fields) {
                    if (!field.isAccessible()) {
                        field.setAccessible(true);
                        if("id".equals(field.getName())){
                            field.setAccessible(true);
                            return field.get(object);
                        }
                    }
                }
                cls = cls.getSuperclass();
            }
        }
        return null;
    }


}